<?php

/**
 * generates links with the primary key for Crud actions
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: PkLink.php 38 2009-02-18 17:12:39Z monzee $
 */
class Crud_PkLink
{
    protected $_view;

    public function setView($view)
    {
        $this->_view = $view;
    }

    /**
     * generate link with primary key
     *
     * @param array  $values The tuple
     * @param array  $pkeys  Array of primary keys
     * @param string $action Action to call
     */
    public function pkLink($pkeys, $values, $action)
    {
        $url = array('action' => $action, 'sort' => null, 'order' => null, 'page' => null);
        foreach ($pkeys as $pk) {
            $url[urlencode($pk)] = urlencode($values[$pk]);
        }
        return $this->_view->url($url);
    }

}
